﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CombatAutomationTheater;
using GameBoard;

namespace XMLCharSheets
{
    class CharacterSheets
    {
        public const string AllSystemsString = "All";

        //Every sheet in the database.
        private static List<CharacterSheet> _allCharacters = new List<CharacterSheet>();
        
        /// <summary>
        /// Registers the sheet and stores it to the active session list (Full roster)
        /// </summary>
        /// <param name="newSheet"></param>
        public static void RegisterSheet(CharacterSheet newSheet)
        {
            _allCharacters.Add(newSheet);
            FullRoster.Add(newSheet);
        }

        private static ObservableCollection<CharacterSheet> _fullRoster = new ObservableCollection<CharacterSheet>();
        
        /// <summary>
        /// Every sheet available in the active session
        /// </summary>
        public static ObservableCollection<CharacterSheet> FullRoster
        {
            get { return _fullRoster; }
            set { _fullRoster = value; }
        }

        public static void SetActiveSystemTo(ISystemConstants chosenSystem)
        {
            FullRoster.Clear();
            IEnumerable<CharacterSheet> target;
            if (chosenSystem.SystemIDProperty.Equals(AllSystemsString))
            {
                target = _allCharacters;
            }
            else
            {
                target =  _allCharacters.Where(x => x.Ruleset.Equals(chosenSystem.SystemIDProperty));
            }

            foreach (var cur in target)
            {
                FullRoster.Add(cur);
            }
            VisualsViewModel.Instance.ArrowKeyDistance = chosenSystem.ArrowKeyDistance;
        }

    }
}
